using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
//
using SJBotGame.SJBotGameComponents;

namespace SJBotGame
{
    public class SJBotTitleDraw
    {
        private Rectangle rect;
        public Rectangle Rect { get { return rect; } set { rect = value; } }
        //
        private bool highlight;
        public bool Highlight { get { return highlight; } set { highlight = value; } }
        //
        private SJBotTitle title;
        public SJBotTitle Title { get { return title; } set { title = value; } }
        //
		public static Color bgColor = Color.White;
		public static Color inColor = Color.Black;
		//
        public SJBotTitleDraw(SJBotTitle title, Rectangle rect)
        {
            this.title = title;
            this.rect = rect;
            this.highlight = false;
        }
        public SJBotTitleDraw(Rectangle rect)
        {
            this.title = null;
            this.rect = rect;
            this.highlight = false;
        }
        //
        public void DrawNullTitle(Graphics formGraphics)
        {
            SolidBrush bgBrush = new SolidBrush(bgColor);
            formGraphics.FillRectangle(bgBrush, rect);
            bgBrush.Dispose();
        }
        public void Draw(Graphics formGraphics)
        {
            if (title == null)
            {
                DrawNullTitle(formGraphics);
                return;
            }
			Rectangle _rect = rect;
			//
			SolidBrush bgBrush = new SolidBrush(GetTitleColor(title.TitleID));
            Pen borderPen = new Pen(inColor);
            SolidBrush drawBrush = new SolidBrush(inColor);
            //
            Font textFont = new Font("Arial", 6);
            StringFormat textFormat = new StringFormat();
            textFormat.Alignment = StringAlignment.Center;
            textFormat.LineAlignment = StringAlignment.Center;
            //
            if (Highlight)
            {
//				SolidBrush selectedBrush = new SolidBrush(Color.Silver);
//	            formGraphics.FillRectangle(selectedBrush, _rect);
//				selectedBrush.Dispose();
				_rect.Inflate(-3, -3);
            }
            formGraphics.FillRectangle(bgBrush, _rect);
            formGraphics.DrawRectangle(borderPen, _rect);
            formGraphics.DrawString(title.ToString(), textFont, drawBrush, _rect, textFormat);
            //
            bgBrush.Dispose();
            borderPen.Dispose();
            drawBrush.Dispose();
            textFont.Dispose();
            textFormat.Dispose();
        }
        public static Color GetTitleColor(int titleID)
        {
			switch (titleID)
			{
			case 0 : return Color.Red;
			case 1 : return Color.Green;
			case 2 : return Color.Blue;
			case 3 : return Color.Yellow;
			case 4 : return Color.Orange;
			case 5 : return Color.Brown;
			default: return Color.White;
			}
		}
   }
}
